package com.cskaoyan.controller;


import com.cskaoyan.bean.baseresultVO.BaseData;
import com.cskaoyan.bean.baseresultVO.BaseParam;
import com.cskaoyan.bean.baseresultVO.BaseRespVo;
import com.cskaoyan.bean.domain.Storage;
import com.cskaoyan.bean.storageBeans.StorageVo;
import com.cskaoyan.service.StorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @User: Yr
 * @Date: 2021/11/29
 * @Description:
 */
@RestController
@RequestMapping("/admin/storage")
public class StorageController {

    @Autowired
    StorageService storageService;

    @RequestMapping("create")
    public BaseRespVo create(MultipartFile file) throws IOException {
        StorageVo storageVo = storageService.create(file);
        return BaseRespVo.ok(storageVo);
    }

    @RequestMapping("list")
    public BaseRespVo list(String name, String key, BaseParam baseParam) {
        BaseData baseData = storageService.list(name,key,baseParam);
        return BaseRespVo.ok(baseData);
    }

    @RequestMapping("update")
    public BaseRespVo update(@RequestBody Storage storage) {
        Storage sto = storageService.update(storage);
        return BaseRespVo.ok(sto);
    }

    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody Storage storage) {
        storageService.delete(storage);
        return BaseRespVo.ok(null);
    }



}

